/*
 * Copyright (C) 2008 DVOSoft, Inc.
 *
 * All rights reserved.
 */
package dvo.infact;

import java.util.List;

import com.informatica.powercenter.sdk.SDKException;
import com.informatica.powercenter.sdk.repository.IGroup;
import com.informatica.powercenter.sdk.server.IInputBuffer;
import com.informatica.powercenter.sdk.server.IOutputBuffer;
import com.informatica.powercenter.sdk.server.ct.PCTPartitionDriver;

/**
 * The runtime of the pivot transform.
 *
 * @author Vinayak R. Borkar &lt;vinayakb@blacktitan.com&gt;
 */
class PivotPartitionDriverImpl extends PCTPartitionDriver {
    private int[][] targetMatrix;

    PivotPartitionDriverImpl(int[][] targetMatrix) {
        this.targetMatrix = targetMatrix;
    }

    @Override
    public void deinit() throws SDKException {

    }

    @Override
    public void eofNotification(IGroup arg0) throws SDKException {

    }

    @Override
    public void execute(IGroup arg0, IInputBuffer arg1) throws SDKException {
        IOutputBuffer outputBuffer = (IOutputBuffer) getOutputBuffers().get(0);
        int n = arg1.getNumRowsAvailable();
        for (int r = 0; r < n; ++r) {
            for (int i = 0; i < targetMatrix.length; ++i) {
                for (int o = 0; o < targetMatrix[i].length; ++o) {
                    StringBuffer buf = new StringBuffer();
                    arg1.getStringBuffer(r, targetMatrix[i][o], buf);
                    outputBuffer.setString(0, o, buf.toString());
                }
                outputBuffer.flush(1);
            }
        }
    }

    @Override
    public void init(List inBufInits, List outBufInits) throws SDKException {
    }

    @Override
    public void inputTransaction(int arg0) throws SDKException {

    }
}
